//
//  main.m
//  OC6_字典集合作业省市区网上答案
//
//  Created by dllo on 15/10/31.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "Country.h"
#import "Province.h"
#import "City.h"

int main(int argc, const char * argv[])
{
    NSString * path = @"/Users/dllo/Desktop/省市区/area.txt";//导入文档地址
    NSString * data = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
    NSArray * dataArr = [data componentsSeparatedByString:@"\n"];
    
    
    
    Country * country = [Country countryWithName:@"china" array:[NSMutableArray array]];
    NSMutableArray * proArr = [country array];
    for (NSString*str in dataArr) {
        //省
        if (![str hasPrefix:@" "]) {
            Province * province = [Province provinceWithName:str array:[NSMutableArray array]];
            [proArr addObject:province];
        }
        //市
        else if ([str hasPrefix:@" "] && ![str hasPrefix:@" "]){
            City * city = [City cityWithName:str array:[NSMutableArray array]];
            Province * pro = [proArr lastObject];
            NSMutableArray * cityArr = [pro array];
            [cityArr addObject:city];
        }
        //区
        else{
            Province * pro = [proArr lastObject];
            City * city = [[pro array]lastObject];
            NSMutableArray * areaArr = [city array];
            [areaArr addObject:str];
        }
    }
    //遍历
    for (Province * province in [country array]) {
        NSLog(@"%@",[province name]);
        for (City * city in [province array]) {
            NSLog(@"%@",[city name]);
            for (NSString * str in [city array]) {
                NSLog(@"%@",str );
            }
        }
    }
    
    return 0;
}
